home *** CD-ROM | disk | FTP | other *** search
- package horst;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.Shape;
- import java.net.URL;
- import java.util.StringTokenizer;
- import java.util.Vector;
- import javax.swing.JComponent;
- import javax.swing.JScrollPane;
-
- public class FrameSetView extends BlockView {
- FrameSetPanel m_panel;
- Component[] m_framesetChildren;
- URL[] m_frameURLs;
- FrameConstraint[] m_constraints;
- int m_orientation = 0;
- boolean m_bLoadedFrames;
-
- public FrameSetView(View parent, Element e, HTMLPane container) {
- super(parent, e, container);
- }
-
- Object getFrame(int idx) {
- if (this.m_framesetChildren != null && this.m_framesetChildren.length > idx && this.m_framesetChildren[idx] instanceof HTMLWindow) {
- HTMLWindow wnd = (HTMLWindow)this.m_framesetChildren[idx];
- if (wnd != null) {
- return ((JScrollPane)wnd).getViewport().getView();
- }
- }
-
- return null;
- }
-
- HTMLPane getFrame(String frameName) {
- if (frameName != null) {
- if (frameName.equalsIgnoreCase("_self")) {
- return super.m_container;
- }
-
- if (frameName.equalsIgnoreCase("_top")) {
- HTMLPane p = super.m_container;
-
- while(p != null) {
- if (p instanceof HTMLPane && !p.m_props.m_bIsFrame) {
- return p;
- }
-
- Component parent = ((Component)p).getParent();
- if (parent == null) {
- HTMLPane hp = null;
- break;
- }
- }
-
- return null;
- }
-
- for(int i = 0; i < this.m_framesetChildren.length; ++i) {
- if (this.m_framesetChildren[i] instanceof HTMLWindow) {
- HTMLWindow p = (HTMLWindow)this.m_framesetChildren[i];
- HTMLPane html = p.getHTMLPane();
- String name = html.m_props.m_frameName;
- if (name != null && name.equals(frameName)) {
- return html;
- }
- }
- }
- }
-
- return null;
- }
-
- protected int getMinimumSpan(int axis) {
- return this.getPreferredSpan(axis);
- }
-
- protected int getPreferredSpan(int axis) {
- Dimension dim = super.m_container.getBrowserDimension();
- return axis == 1 ? dim.width : dim.height;
- }
-
- protected void init() {
- this.m_bLoadedFrames = false;
- this.m_panel = new FrameSetPanel();
- super.m_container.add(this.m_panel);
- this.m_panel.setBackground(Color.white);
- int nCount = super.m_elem.getElementCount();
- FrameSetLayout layoutManager = new FrameSetLayout();
- boolean bAddSplitterBars = true;
- String atts = (String)super.m_elem.getAttribute("frameborder");
- if (!super.m_container.m_preferences.m_bAlwaysSizableFrames && atts != null && (atts.equalsIgnoreCase("0") || atts.equalsIgnoreCase("no"))) {
- layoutManager.setAlwaysConstraintLayout(true);
- bAddSplitterBars = false;
- }
-
- Vector temp = new Vector();
- Vector urlVec = new Vector();
- this.m_framesetChildren = new JComponent[nCount];
- URL refURL = super.m_elem.getDocument().getBaseURL();
-
- for(int i = 0; i < nCount; ++i) {
- Element elem = super.m_elem.getElementAt(i);
- if (elem.getType() == 36) {
- HTMLWindow htmlWnd = new HTMLWindow(false);
- HTMLPane html = htmlWnd.getHTMLPane();
- html.m_preferences.m_bShowToolTip = false;
- html.m_props.m_bIsFrame = true;
- html.m_props.m_framesetView = this;
- html.m_props.m_frameBaseDocument = super.m_container.getDocument();
- String name = (String)elem.getAttribute("name");
- if (name != null) {
- html.m_props.m_frameName = name;
- }
-
- String src = (String)elem.getAttribute("src");
- URL url = null;
- if (refURL != null) {
- url = Utilities.getURL(refURL, src);
- } else {
- url = Utilities.getURL(src);
- }
-
- if (url != null) {
- html.openPage(url);
- }
-
- urlVec.addElement(url);
- temp.addElement(htmlWnd);
- } else if (elem.getType() == 35) {
- FrameSetView fv = (FrameSetView)super.m_container.m_viewFactory.createView((View)null, elem, super.m_container);
- temp.addElement(fv.m_panel);
- }
- }
-
- this.m_framesetChildren = new Component[temp.size()];
- temp.copyInto(this.m_framesetChildren);
- this.m_frameURLs = new URL[urlVec.size()];
- urlVec.copyInto(this.m_frameURLs);
- if ((atts = (String)super.m_elem.getAttribute("cols")) != null) {
- layoutManager.setOrientation(0);
- this.parseAttributes(atts);
- } else if ((atts = (String)super.m_elem.getAttribute("rows")) != null) {
- layoutManager.setOrientation(1);
- this.parseAttributes(atts);
- } else {
- layoutManager.setOrientation(0);
- this.m_constraints = new FrameConstraint[this.m_framesetChildren.length];
-
- for(int i = 0; i < this.m_framesetChildren.length; ++i) {
- this.m_constraints[i] = new FrameConstraint();
- if (i == 0) {
- this.m_constraints[i].percent = 1.0F;
- } else {
- this.m_constraints[i].percent = 0.0F;
- }
- }
- }
-
- this.m_panel.setLayout(layoutManager);
-
- for(int i = 0; i < this.m_framesetChildren.length; ++i) {
- layoutManager.setConstraints(this.m_framesetChildren[i], this.m_constraints[i]);
- this.m_panel.add(this.m_framesetChildren[i]);
- if (bAddSplitterBars && i != this.m_framesetChildren.length - 1 && this.m_framesetChildren.length > 1) {
- FrameSplitterBar splitbar = new FrameSplitterBar(this.m_orientation);
- splitbar.setResizable(true);
- this.m_panel.add(splitbar);
- }
- }
-
- }
-
- protected Rectangle layout(int x, int y, int width, LayoutInfo info) {
- if (!super.m_container.getFramesEnabled()) {
- super.m_bounds.setBounds(0, 0, 0, 0);
- return super.m_bounds;
- } else {
- Dimension d = super.m_container.getBrowserDimension();
- super.m_bounds.setBounds(x, y, width, d.height);
- this.m_panel.setBounds(super.m_bounds);
- return super.m_bounds;
- }
- }
-
- protected void makeChildren(ViewFactory factory) {
- }
-
- public void paint(Graphics g, Shape alloc) {
- this.m_panel.invalidate();
- }
-
- void parseAttributes(String attStr) {
- if (attStr != null) {
- StringTokenizer st = new StringTokenizer(attStr, ",");
- int nCols = st.countTokens();
- this.m_constraints = new FrameConstraint[nCols];
- if (nCols > 0) {
- for(int i = 0; st.hasMoreTokens(); ++i) {
- String token = st.nextToken();
- this.m_constraints[i] = new FrameConstraint();
- Integer val = null;
- if ((val = Utilities.parseInteger(token, '%')) != null) {
- this.m_constraints[i].type = 1;
- this.m_constraints[i].percent = (float)val / 100.0F;
- } else if ((val = this.parseWildCard(token)) != null) {
- this.m_constraints[i].type = 2;
- this.m_constraints[i].wildcard = val;
- } else {
- val = Utilities.getInteger(token);
- this.m_constraints[i].type = 0;
- this.m_constraints[i].pixels = val;
- }
- }
- }
- }
-
- }
-
- Integer parseWildCard(String token) {
- Integer val = null;
- int idx;
- if ((idx = token.indexOf(42)) != -1) {
- try {
- token = token.substring(0, idx).trim();
- val = new Integer(token);
- } catch (NumberFormatException var4) {
- return new Integer(1);
- }
- }
-
- return val;
- }
-
- protected void reset() {
- this.m_bLoadedFrames = false;
- super.reset();
- }
- }
-